package com.szosen.util;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.szosen.jkzj.R;
/**
 * 显示三列文本的适配器，设置第一行为标题行，背景与内容行不同
 */
public class ThreeCloumAdpter extends BaseAdapter {
	private static final int LENGHT = 3;
	private List<String[]> datas;
	private Context context;

	public ThreeCloumAdpter(Context context, List<String[]> datas) {
		this.context = context;
		this.datas = datas;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		// 只有为空时才构造
		if (convertView == null) {
			holder = new Holder();
			holder.dataET = new TextView[LENGHT];
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.list_item_all_record, null);
			holder.dataET[0] = (TextView) convertView
					.findViewById(R.id.list_data_1);
			holder.dataET[1] = (TextView) convertView
					.findViewById(R.id.list_data_2);
			holder.dataET[2] = (TextView) convertView
					.findViewById(R.id.list_data_3);

			holder.layout = (LinearLayout) convertView
					.findViewById(R.id.record_layout);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		
		if(position<datas.size()){
			String[] line = datas.get(position);
			for (int i = 0; i < LENGHT; i++) {
				if(line[i]==null){
					continue;
				}
				String item;
				if (line[i].length() > 200)// 显示心电太长了,只显示部分
					item = line[i].substring(0, 20) + "...";
				else
					item = line[i];
				holder.dataET[i].setText(item);
			}
		}
	//	holder.layout.setBackgroundResource(R.drawable.button_selector);
	/*	if (position == 0) {
			holder.layout.setBackgroundResource(R.color.record_title);
		} else {
			// 设置内容栏的背景
			holder.layout.setBackgroundResource(R.drawable.button_selector);
		}*/
		return convertView;
	}

	/***
	 * 用于暂存数据
	 * 
	 * @author jiqunpeng
	 * 
	 *         创建时间：2013-12-20 下午3:11:21
	 */
	class Holder {
		TextView[] dataET;// 显示的内容
		LinearLayout layout;// 设定背景
	}
}
